package com.server.server;

import java.util.ArrayList;
import java.util.List;

import org.apache.mina.core.session.IoSession;

import com.server.app.PlayerManager;
import com.server.object.Player;
import com.server.object.PlayerData;
import com.server.protocols.SProtocols;
import com.server.request.GetPlayerDataReq;
import com.server.response.GetPlayerDataResp;
import com.webserver.server.net.BaseMessage;
import com.webserver.server.net.BaseServer;

public class GetPlayerDataServer implements BaseServer {
	public int GetProtocol() {
		return SProtocols.GET_PLAYERS;
	}

	public BaseMessage GetRequest() {
		return new GetPlayerDataReq();
	}

	public BaseMessage handle(IoSession is,BaseMessage request) {
		Player player = PlayerManager.GetInstance().GetPlayer(request.getUserInfo().uid);
		GetPlayerDataResp resp = null;
		List<PlayerData> data = new ArrayList<PlayerData>();
		if(player != null) {
			if(player.room != null) {
				data = player.room.GetPlayerData(player.uid);
			}
			resp = new GetPlayerDataResp(data);
			
		}else {
			resp = new GetPlayerDataResp(data);
		}
		
		return resp;
	}
}